#ifndef QUOTE_H
#define QUOTE_H

#include <iostream>
#include <string>

using namespace std;
class Quote {
  friend double print_total(ostream &, const Quote &, size_t); //定义为友元函数
public:
  /*	Quote() = default;//C++11新特性*/
  Quote(); //默认构造函数
  Quote(const string &book, double sales_price)
      : BookNo(book), price(sales_price){}; //构造函数
  Quote(const Quote &quote1)
      : BookNo(quote1.BookNo), price(quote1.price) //拷贝构造函数
  {
    cout << "拷贝构造函数" << endl;
  }

  Quote(const Quote &&quote3)
      : BookNo(move(quote3.BookNo)), price(move(quote3.price)) //移动构造函数
  {
    cout << "移动构造函数" << endl;
  }

  string isbn() const { return BookNo; }; //保存每本书籍的编号
  virtual double net_price(size_t n) const //定义为虚函数，让派生类自己定价
  {
    cout << "Quote" << endl;
    return n * price;
  }
  virtual void debug() {
    cout << "This is Quote Class" << endl;
    cout << "ISBN: " << BookNo << endl;
    cout << "Price: " << price << endl;
  }

private:
  string BookNo; //书籍的ISBN编号
protected:
  double price; //普通状态下不打折的价格，C++11不支持非静态变量的类内初始化
};

double print_total(ostream &os, const Quote &item, size_t n) {
  //动态绑定的实例
  double ret = item.net_price(n);
  os << "ISBN: " << item.isbn() << endl;
  os << "sold: " << n << " total price: " << ret << endl;
  return ret;
}

class bulk_quote : public Quote {
public:
  bulk_quote(); //默认构造函数
  bulk_quote(string &book, double p, size_t ny, double disc)
      : Quote(book, p), min_qty(ny), discount(disc){}; //派生类构造函数

  // 	bulk_quote(const bulk_quote& rhs):Quote(rhs){}//继承拷贝构造函数
  // 	bulk_quote& operator=(const bulk_quote& rhs)
  // 	{
  // 		Quote::operator=(rhs);//继承拷贝赋值运算符
  // 		return *this;
  // 	}
  // 	bulk_quote(const bulk_quote&& rhs):Quote(move(rhs)){}//继承移动构造函数
  // 	bulk_quote& operator=(const bulk_quote&& rhs)
  // 	{
  // 		Quote::operator=(move(rhs));//继承拷贝赋值运算符
  // 		return *this;
  // 	}这就是作怪的继承构造函数啦！

  // virtual double net_price(size_t) const;//重新声明，与下面的方式作用相同
  double net_price(size_t cnt) const
  /* override*/ //允许派生类显示的注明它将使用哪个成员函数改写基类的虚函数
  {
    cout << "bulk_uote" << endl;
    if (cnt >= min_qty) {
      cout << cnt * (1 - discount) * price << endl;
      return cnt * (1 - discount) * price;
    } else {
      return 0;
    }
  }
  void debug() {
    cout << "This is bulk_quote Class" << endl;
    cout << "DISCOUNT: " << discount << endl;
    cout << "Min_qty: " << min_qty << endl;
    cout << "Price: " << price << endl;
  }
  //除了自定义的版本，还可以访问其基类的相应成员
private:
  double discount; //折扣额，C++11新标准
  size_t min_qty;  //适用折扣的最低购买量
};

class number_quote : public Quote {
public:
  number_quote(); //默认构造函数
  number_quote(string &book, double p, size_t n, double disc)
      : Quote(book, p), number1(n), discount1(disc){}; //派生类构造函数
  // virtual double net_price(size_t) const;//重新声明，与下面的方式作用相同
  double net_price(size_t cnt)
      const override //允许派生类显示的注明它将使用哪个成员函数改写基类的虚函数
  {
    if (cnt >= number1) {
      return number1 * (1 - discount1) * price + (cnt - number1) * price;
    } else {
      return cnt * (1 - discount1) * price;
    }
  }
  void debug() override {
    cout << "This is number_quote Class" << endl;
    cout << "DISCOUNT: " << discount1 << endl;
    cout << "Max_qty: " << number1 << endl;
    cout << "Price: " << price << endl; // protected成员也可以包含
  }
  //除了自定义的版本，还可以访问其基类的相应成员
private:
  double discount1; //折扣额，C++11新标准
  size_t number1;   //给定限量
};
#endif // QUOTE_H